package leetcode.leetcode387;

/**
 * @author czt
 * @version 1.0
 * @since 2025/1/7
 * <p>
 * 找出第一个不重复的字符
 */
public class Leetcode387 {

    public int firstUniqChar(String s) {
        int[] array = new int[26];
        char[] chars = s.toCharArray();
        for (char ch : chars) {
            // 统计每个字符出现的次数
            array[ch - 'a']++;
        }
        for (int i = 0; i < chars.length; i++) {
            char c = chars[i];
            if (array[c - 'a'] == 1) {
                return i;
            }
        }
        return -1;
    }

}
